/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {number} n
 * @return {TreeNode[]}
 */
var generateTrees = function (n) {
    // let visited = new Array(n).fill(false)
    const dfs = function (left, right) {
        if(left > right) return null
        if (left === right) return new TreeNode(left)
        for (let i = left; i <= right; i++) {
           const root = new TreeNode(i)
           root.left = dfs(left, i - 1)
           root.right = dfs(i + 1, right)
        }
    }
};